package com.bestcem.xm.user.mq.receive;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;


/**
 * 消息接收
 *
 * @author zhijian.lin <zhijian.lin@idiaoyan.com>
 * @version v1.0
 * @date 2022/3/9 18:30
 */
//@Slf4j
//@Component
@Deprecated
public class UserDelayMqReceive {

    //@Resource
    //private OrganizationService organizationService;

    /**
     * 监听 用户中心延迟队列MQ
     */
    //@RabbitListener(queues = "#{userDelayQueue.name}", concurrency = "${app.user.rabbitmq.userDelayQueue.concurrency:10}")
    //@RabbitHandler
    public void handlerApp(Message message, Channel channel) {
        //try {
        //    if (log.isInfoEnabled()) {
        //        log.info("[USER] 用户中心延迟队列收到消息:{}", Base64.getEncoder().encodeToString(dto.getBody()));
        //    }
        //    MsgPackFormatUtil.MqMessage mqMessage = MsgPackFormatUtil.mqDecode(dto.getBody());
        //    if (mqMessage == null) {
        //        log.error("[USER] 用户中心延迟消息解析失败:" + Base64.getEncoder().encodeToString(dto.getBody()));
        //        channel.basicNack(dto.getMessageProperties().getDeliveryTag(), false, false);
        //        return;
        //    }
        //    if (log.isInfoEnabled()) {
        //        log.info("[USER] 用户中心延迟队列消息体 {}", JSON.toJSONString(mqMessage));
        //    }
        //    // 用户中心套餐降级消息邮件发送
        //    if (UserTopics.USER_EMAIL_SMS_TOPIC.equals(mqMessage.getTopic())) {
        //        PackageExpireMessage packageExpireMessage = MsgPackFormatUtil.mapToObj(mqMessage.getData(), PackageExpireMessage.class);
        //        if (log.isInfoEnabled()) {
        //            log.info("[USER] 用户中心套餐降级消息邮件发送 {}", JSON.toJSONString(packageExpireMessage));
        //        }
        //        PackExpireEmailDTO expireEmailDTO = new PackExpireEmailDTO();
        //        BeanUtils.copyProperties(packageExpireMessage, expireEmailDTO);
        //        ServiceResult<Boolean> result = organizationService.sendPackExpireSmsAndEmail(expireEmailDTO);
        //        if (!result.getData() && log.isInfoEnabled()) {
        //            log.info("[USER] 用户中心套餐降级消息邮件发送失败 {}", JSON.toJSONString(packageExpireMessage));
        //        }
        //    }
        //    channel.basicAck(dto.getMessageProperties().getDeliveryTag(), false);
        //} catch (Exception e) {
        //    String errorMsg = Base64.getEncoder().encodeToString(dto.getBody());
        //    log.error("[USER] 用户中心延迟队列消息处理异常 {}", errorMsg, e);
        //    try {
        //        channel.basicNack(dto.getMessageProperties().getDeliveryTag(), false, false);
        //    } catch (IOException ex) {
        //        log.error("[USER]: 用户中心延迟队列消息确认失败", ex);
        //    }
        //}
    }
}
